<template>
  <div class="page" @scroll="paperScroll" ref="page">
    <!--header-->
  <div class="pt-header">
    <h1 class="header-logo"><a href="#" title="猴趣乐">LOGO</a> </h1>  
  </div>
<!--slide-->
      <div class="swiper-container">  
        <div class="swiper-wrapper">
            <div class="swiper-slide" v-for="(img, index) in imgArray"><img :src='img.imgurl'></div>
        </div>
        <div class="swiper-pagination swiper-pagination-white"></div>
      </div> 
 <!--list-->
  <sticky>
      <div class="filter">
        <ul>
          <li>猴毛：***</li>
          <li>L猴毛：***</li>
          <li>乐值：***</li>
          <li>领取：***</li>
        </ul>
        <ul>
          <li><router-link tag="div" class="backhome" to="/ranking" replace></router-link></li>
        </ul>
      </div>
    </sticky>     
<!--list-->
    <sticky>
      <div class="filter">
        <ul class="status">
          <li v-for="(item, index) in category" :class="{'active': item.key == params.status}" @click="changeCategory(item.key)" :key="index">{{$t(item.value)}}</li>
        </ul>
        <ul class="order" v-show="params.status != 5">
          <li :class="{'active': item.value == params.orderBy,'up': params.sort == 0}" @click="changeOrder(item.value)" v-for="(item, index) in order" :key="index">{{$t(item.value)}}</li>
        </ul>
      </div>
    </sticky>
    <div class="records" v-if="params.status == 5">
      
    </div>
    <!-- 商品 -->
    <div class="monkeys" v-else>
      
      <div class="panel" v-for="(item,index) in homeList" :key="index">
        <div class="list-item" @click="toMonkey(item)">
          <div class="img">
            <img :src="item.img"  alt="">
            
          </div>
          <ul class="minfo">
            <li style="font-size: 16px;"><h3>{{ item.name}}</h3></li>
            <li><span style="display: block;">高潮利器 三马达四重高潮 欲望释放高潮利器 三马达四重高潮 欲望释放</span></li>
            <li style="color:red;">
              <span v-if = "item.startTime">起拍价：</span>￥{{ item.price}}</br>
              <span v-if = "item.startTime">竞拍时间：
              <count-down :currentTime="item.sysTime" :startTime="item.startTime" :endTime="item.endTime"  :endText="$t('竞拍结束')"></count-down>
              </span>
            </li>
            
          </ul>
          <div class="tag" v-if="item.type > 0">
            <i class="ico" :class="{'sell':item.type == 1,'love':item.type == 2}"></i>
            <span>{{ item.price }}</span>
          </div>
        </div>
      </div>
      <infinite-loading @infinite="initTabData"  v-if="params.status != ''" ref="infiniteLoading">
        <span slot="no-more"></span>
        <div slot="no-results" v-if="params.status != ''">
          <br>
          <empty></empty>
        </div>
        <div slot="no-results" v-else></div>
        <spinner slot="spinner" type="lines"></spinner>
      </infinite-loading>
    </div>
    <div class="panel" v-if="recommendList.length > 0 && showRecommend && params.status == ''">
      <empty></empty>
      
      
    </div>
   
    
  </div>
</template>


<script>
  import {
    Group,
    XInput,
    Sticky,
    TransferDom,
    Spinner,
    Popup,
    XButton,
    Box
  } from 'vux'
  import Swiper from 'swiper';
  import './common/swiper.min.css';
  import lottery from './common/lottery.vue'
  import empty from './common/empty.vue'
  import CountDown from './common/countdown.vue'
 // import CountDown from './common/vue2-countdown.vue'
  import InfiniteLoading from 'vue-infinite-loading';
  export default {
    directives: {
      TransferDom
    },
    components: {
      Group,
      XInput,
      lottery,
      Sticky,
      empty,
      CountDown,
      InfiniteLoading,
      Spinner,
      Popup,
      XButton,
      Box
    },
    data() {
      return {
        
         mark: 0, //比对图片索引的变量 
        imgArray: [],
        category: [],
        order: [{
            name: '销量',
            value: '1'
          },
          {
            name: '价格',
            value: '2'
          }
        ],
        homeList: [],
        params: {
          orderBy: '1', //1:代数,2:体重,3:收益
          sort: '0', //0:升 1:降
          status: '', //0:正常 1: 出售 2:繁殖,不传值显示全部
          current: 1,
          startGen: '',
          endGen: '',
          startGrow: '',
          endGrow: '',
          startBear: '',
          endBear: '',
          startMakeMoney: '',
          endMakeMoney: '',
          startBearNum: '',
          endBearNum: '',
          startWeight: '',
          endWeight: '',
        },
        showFilter: false,
        recommendList: [],
        historyList: [],
        showRecommend: false,
        activeRecord: 1,
        buyCurrent: 1,
        breedCurrent: 1,
        buyHistoryList: [],
        breedHistoryList: [],
        loadMore0: false,
        loadMore1: false,
        scrollTop_home: 0,
        monkeyStatus: ['空闲','出售中','生育挂单','参战中','采集中']
      }
    },
    mounted() {
       
            
           
      this.$nextTick(function() {
       
        this.initData();
      });
    },
    activated() {
      this.$refs.page.scrollTop = this.$store.state.scrollTop_home;
    },
    
    methods: {
       toMonkey(item) {
        if(item.startTime){
           this.$router.push('/auction/' + item.id)
        }else{
        this.$router.push('/monkey/' + item.id)
        }
      },
      initData($state) {
        this.$http
          .get('/goods/index')
          .then(res =>{
          var swiper = new Swiper('.swiper-container', {
                pagination: '.swiper-pagination',
                paginationClickable: true,
                loop: true,
                speed: 600,
                autoplay: true,
                onTouchEnd: function() {
                    swiper.startAutoplay()
                }
            });
          if(res.code == 200){
            this.imgArray = res.result.banner;
            this.params.status = res.result.level[0].key;
            this.category = res.result.level;
           
          }else {
              this.$vux.toast.text(res.msg)
            }

          }).catch(function(error) {});


       
      },
      initTabData($state) {
        this.$http
          .post('/goods/gclist/' + this.params.status , this.params)
          .then(res =>{
          var swiper = new Swiper('.swiper-container', {
                pagination: '.swiper-pagination',
                paginationClickable: true,
                loop: true,
                speed: 600,
                autoplay: true,
                onTouchEnd: function() {
                    swiper.startAutoplay()
                }
            });
          if(res.code == 200){
          this.homeList  = this.homeList.concat(res.result.records);

            $state.loaded();
                if (res.result.current < res.result.pages) {
                  this.params.current += 1;
                } else {
                  $state.complete();
                }
          }else {
              this.$vux.toast.text(res.msg)
            }

          }).catch(function(error) {});

       
      },
      getRecommend() {
        if (this.showRecommend && this.params.status == '') {
          this.$http
            .get(`/game/recentlyThree`)
            .then(res => {
              if (res.code == 200) {
                this.recommendList = res.result;
              } else {}
            })
            .catch(function(error) {});
        }
      },
      feedAllConfirm() {
        var that = this;
        this.$vux.confirm.show({
          title: '提示',
          content: `使用此功能需要绑定瑞波钱包地址，每只小猴收取5猴毛服务费！注意半个小时仅能使用一次此功能。`,
          confirmText: '一键喂食',
          cancleText: '算了',
          onConfirm() {
            that.feedAll()
          }
        })
      },
      feedAll() {
        this.$vux.loading.show({
          text: '请稍后'
        })
        this.$http
          .post(`gameCastle/v2/automaticFeed`,this.params).then(res => {
            this.$vux.loading.hide()
            
            if (res.code == 200) {
              this.$vux.toast.text('一键喂食任务提交成功，请耐心等待。')
            } else {
              this.$vux.toast.text(res.msg)
            }
          })
          .catch(function(error) {});
      },
      changeHistory(index) {
        this.activeRecord = index;
        if (index == 0) {
          this.historyList = this.breedHistoryList
        } else {
          this.historyList = this.buyHistoryList
        }
      },

      resetFilter() {
        this.params.startGen = '';
        this.params.endGen = '';
        this.params.startGrow = '';
        this.params.endGrow = '';
        this.params.startBear = '';
        this.params.endBear = '';
        this.params.startMakeMoney = '';
        this.params.endMakeMoney = '';
        this.params.startBearNum = '';
        this.params.endBearNum = '';
        this.params.startWeight = '';
        this.params.endWeight = '';
      },
      enterFilter() {
        this.$nextTick(() => {
          this.resetData()
          this.showFilter = false
        });
      },
      resetData() {
        this.params.current = 1;
        this.homeList = [];
        this.$refs.infiniteLoading.$emit('$InfiniteLoading:reset');
      },
      paperScroll(e) {
        this.scrollTop_home = e.srcElement.scrollTop
      },
      
      more(index) {
        if (index == 0) {
          this.breedCurrent += 1;
          this.getBreedHistory()
        } else {
          this.buyCurrent += 1;
          this.getBuyHistory()
        }
      },
      getBuyHistory() {
        this.$http
          .post(`/game/monkeyBuyPage`, {
            current: this.buyCurrent
          })
          .then(res => {
            if (res.code == 200) {
              if (res.result.total > 0) {
                this.buyHistoryList = this.buyHistoryList.concat(res.result.records);
                if (this.activeRecord == 1) {
                  this.historyList = this.buyHistoryList
                }
                if (res.result.current < res.result.pages) {
                  this.loadMore1 = true
                } else {
                  this.loadMore1 = false
                }
              } else {}
            } else {}
          })
          .catch(function(error) {});
      },
      getBreedHistory() {
        this.$http
          .post(`/game/monkeyBearPage`, {
            current: this.breedCurrent
          })
          .then(res => {
            if (res.code == 200) {
              if (res.result.total > 0) {
                this.breedHistoryList = this.breedHistoryList.concat(res.result.records);
                if (this.activeRecord == 0) {
                  this.historyList = this.breedHistoryList
                }
                if (res.result.current < res.result.pages) {
                  this.loadMore0 = true
                } else {
                  this.loadMore0 = false
                }
              } else {}
            } else {}
          })
          .catch(function(error) {});
      },
      // 筛选目录
      changeCategory(value) {
      console.log(value)
        this.params.status = value
        if (value == 5) {
          this.breedCurrent = 1
          this.buyCurrent = 1;
          this.breedHistoryList = [];
          this.buyHistoryList = [];
          this.getBreedHistory()
          this.getBuyHistory()

        } else {
           console.log(value)
            this.resetData()
          
        }
      },
      changeOrder(order) {
        //点击同一个
        if (order == this.params.orderBy) {
          this.params.sort = this.params.sort == 0 ? 1 : 0;
        } else {
          this.params.orderBy = order;
          this.params.sort = 1
        }
        this.resetData()
      },
      statusColor(status) {
        var str = '';
        var color = '';
        switch (status) {
          case 0:
            str = '已挂单'
            color = '#0579c1'
            break;
          case 1:
            str = '等待付款'
            color = '#e64340'
            break;
          case 2:
            str = '等待确认'
            color = '#ed8422'
            break;
          case 3:
            str = '已完成'
            color = '#1aad19'
            break;
          case -1:
            str = '已取消'
            color = '#d9dbee'
            break;
        }
        return color
      }
    }
  }
</script>

<style lang="scss" scoped>
  .swiper-container {
        width: 100%;
        height: 10rem;
        .swiper-wrapper {
            width: 100%;
            height: 100%;
        }
        .swiper-slide {
            background-position: center;
            background-size: cover;
            width: 100%;
            height: 100%;
            img {
                width: 100%;
                height: 100%;
            }
        }
        .swiper-pagination-bullet {
            width:0.833rem;
            height: 0.833rem;
            display: inline-block;
            background: #7c5e53;
        }
    }
  .pt-header {
   min-height: 44px;
  height: 44px; 
  line-height: 40px;  
  position: relative; 
  background-color: #fff; 
  overflow: hidden; 
  }
  .header-logo { position: absolute; left: 1rem; bottom: .7rem; background-size: 180px 180px; background-position: 0 -142px; height: 28px; width: 260px;}
  .header-logo a { 
  display: inline-block; 
  background-size: 16rem 16rem;
  background-position: 0 -7.6rem;
  height: 100%; 
  width: 17rem; 
  text-indent: -9999px;
  background: url(/static/logo1.png) no-repeat; 
  }
   .slide {  
    width: 100%;  
    height: 207px;  
    margin: 0 auto;  
    overflow: hidden;  
    position: relative;  
  }  
  .slideshow {  
    width: 100%;  
    height: 207px;   
  }  
    
   
  .bar {  
    position: absolute;  
    width: 100%;  
    bottom: 10px;  
    margin: 0 auto;  
    z-index: 10;  
    text-align: center; 
    .active {  
    background: red !important;  
  } 
  }  
  .bar span {  
    width: 20px;  
    height: 5px;  
    border: 1px solid;  
    background: white;  
    display: inline-block;  
    margin-right: 10px;  
  }  
  
  .image-enter-active {  
    transform: translateX(0);  
    transition: all 1.5s ease;  
  }  
  .image-leave-active {  
    transform: translateX(-100%);  
    transition: all 1.5s ease;  
  }  
  .image-enter {  
    transform: translateX(100%);  
  }  
  .image-leave {  
    transform: translateX(0);  
  }
  .filter {
    display: flex;
    justify-content: space-between;
    white-space: nowrap; // flex-wrap: wrap;
    font-size: 12px;
    background: #fff;
    height: 40px;
    line-height: 40px;
    padding: 0 12px;
    margin: 0 8px 12px;
    border-radius: 4px;
    box-shadow: 3px 3px 10px 0px rgba(158, 158, 158, 0.4);
    overflow-x: scroll;
    overflow-y: hidden;
    &::-webkit-scrollbar {
      display: none;
    }
    ul {
      display: flex;
      align-items: center;
      li {
        cursor: pointer;
      }
    }
    .status {
      color: $grey;
      li {
        transition: all .3s;
      }
      li:not(:last-child) {
        margin-right: 24px;
      }
      .active {
        color: $green;
        font-size: 14px;
        border-bottom: 2px solid $green;
      }
    }
    .order {
      color: $link;
      margin-left: 20px;
      li+li {
        margin-left: 12px;
      }
      .active:after {
        content: '';
        display: inline-block;
        vertical-align: middle;
        margin-top: -2px;
        width: 12px;
        height: 12px;
        background: url() no-repeat 50%;
        background-size: cover;
      }
      .active.up:after {
        transform: rotate(-180deg)
      }
    }
  }
  .list-item {
    position: relative;
    display: flex;
    height: 100px;
    overflow: hidden;
    .img {
      width: 100px;
      height: 100px;
      font-weight: 300;
      margin-right: 10px;
      position: relative;
      flex-shrink: 0;
      font-size: 10px;
      border-radius: 4px;
      overflow: hidden;
      @media only screen and (min-width: 375px) {
        font-size: 10px;
      }
      @media only screen and (min-width: 414px) {
        font-size: 12px;
      }
      @media only screen and (min-width: 768px) {
        font-size: 14px;
      }
      .id {
        position: absolute;
        color: $grey;
        background-color: rgba(255, 255, 255, .8);
        left: 0;
        top: 6px;
        padding: 0 5px 0 0;
        border-radius: 0 100px 100px 0;
      }
      img {
        width: 100%;
      }
      .info {
        position: absolute;
        left: 2px;
        bottom: 2px;
        line-height: 14px;
        color: #000;
        width: 100%;
        white-space: nowrap;
        padding: 2px;
        p {
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }
    .minfo {
      display: flex;
      
      flex-direction: column;
      font-size: 14px;
      color: $grey;
      white-space: nowrap;
      li:first-child {
        color: #000;
      }
      span {
        vertical-align: middle;
      }
      .progress {
        display: inline-block;
        width: 80px;
        height: 17px;
        border: 1px solid #e8e3e3;
        vertical-align: middle;
        overflow: hidden;
        border-radius: 2px;
        .percent {
          font-size: 12px;
          line-height: 15px;
        }
        .yellow {
          background-color: rgba(3, 169, 244, 0.34);
          height: 100%;
        }
      }
    }
    .tag {
      position: absolute;
      top: -3px;
      right: 0;
      color: $green;
    }
  }
  .find-list {
    // position: absolute;
    // left: 0;
    text-align: center;
    .item {
      display: inline-block;
      vertical-align: middle;
      width: 33.33%; // min-height: 150px;
      border: 4px solid transparent;
      line-height: 1;
      overflow: hidden;
      text-overflow: ellipsis;
      .img {
        position: relative;
        img {
          width: 100%;
          background-color: #e0e2ff;
        }
        .id {
          position: absolute;
          color: $grey;
          background-color: #fff;
          left: 0;
          top: 6px;
          font-size: 10px;
          padding: 3px 5px 3px 0;
          border-radius: 0 10px 10px 0;
        }
        .info {
          font-size: 10px;
          position: absolute;
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          left: 0;
          bottom: 0;
          line-height: 14px;
          color: $grey;
          white-space: nowrap;
          padding: 2px;
        }
      }
      .price {
        text-align: center;
        font-size: 12px;
        padding: 5px 10px;
        color: #333;
      }
    }
  }
  .nomonkey {
    text-align: center;
    h3 {
      color: $tmdark;
      font-size: 20px;
    }
    span {
      font-size: 12px;
      color: $grey;
    }
  }
  .link {
    text-align: center;
    a {
      color: $link;
      font-size: 14px;
    }
  }
  .record-item {
    display: flex;
    .img {
      height: 50px;
      width: 50px;
      margin-right: 10px;
      img {
        width: 100%;
        background-color: #e0e2ff;
      }
    }
    .info {
      height: 50px;
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      white-space: nowrap;
      div {
        display: flex;
        justify-content: space-between;
      }
      .id {
        font-size: 14px;
      }
      .status {
        font-size: 14px;
      }
      .cost {
        font-size: 10px;
        color: $gray;
      }
      .date {
        font-size: 10px;
        color: $grey;
      }
    }
  }
  .tab {
    width: 200px;
    height: 25px;
    border: 1px solid $tmdark;
    display: flex;
    margin: 0 auto 10px;
    border-radius: 4px;
    font-size: 12px;
    div {
      height: 100%;
      width: 100px;
      line-height: 23px;
      text-align: center;
      cursor: pointer;
    }
    .active {
      background-color: $tmdark;
      color: #fff;
    }
  }
  .load {
    text-align: center;
    font-style: 14px;
  }
  .filters {
    overflow: hidden;
    background: #fbf9fe;
    &::-webkit-scrollbar {
      display: none;
    }
    .wrap {
      padding-bottom: 60px;
      height: 100%;
      overflow-y: scroll;
      padding: 12px;
    }
    .button {
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      display: flex;
      .btn {
        width: 50%;
        height: 40px;
        margin: 0;
        border: 0;
        border-radius: 0;
        &:after {
          display: none;
        }
      }
    }
  }
</style>

<style lang="scss">
  .input-range {
    .weui-cells {
      display: flex;
      &:before {
        display: none;
      }
      &:after {
        display: none;
      }
      .weui-cell {
        background: #eeeff1;
        padding: 5px 10px;
        border-radius: 5px;
        &:before {
          display: none;
        }
        input {
          text-align: center;
        }
      }
    }
    .weui-cells__title {
      padding-left: 0;
      color: #666;
      font-weight: 500;
    }
    .dash {
      // width: 80px;
      padding: 0 5px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: #fbf9fe;
      &:before {
        content: '';
        width: 20px;
        height: 1px;
        background: #000;
      }
    }
  }
</style>
